

//tab栏切换

const tab_nav = document.querySelector('.tab-nav')
const pane = document.querySelectorAll('.tab-pane')
tab_nav.addEventListener('click',function(e){
	if(e.target.tagName ==='A')
	{
		tab_nav.querySelector('.active').classList.remove('active')
		e.target.classList.add('active')
		
	}
	//先排除所有
	for(let i=0;i<pane.length;i++)
	{
		pane[i].style.display = 'none'
	}
	pane[e.target.dataset.id].style.display = 'block'
})
const my_checkbox = document.querySelector('#my-checkbox')
const dl = document.querySelector('.dl')
my_checkbox.addEventListener('click',function(){
	if(my_checkbox.checked === true)
	{
		dl.style.background = '#17bb9b'
	}
	else
		dl.style.background = '#CFCDCD'
	// console.log(my_checkbox.checked)
})
//设置本地默认数据
const mr_mysql = {
	username : 123456,
	phone : 17381752915,
	password : 123456,
	id:1
}
// 获取本地存储数据
const arr = JSON.parse(localStorage.getItem('MYSQL')) || []
// console.log(arr);
arr.push(mr_mysql)
 // 点击提交模块
    const form = document.querySelector('form')
    const agree = document.querySelector('[name=agree]')
    const username = document.querySelector('[name=username]')
	const password = document.querySelector('[name= password]')
    form.addEventListener('submit', function (e) {
      e.preventDefault()
      // 判断是否勾选同意协议
      if (!agree.checked) {
        return myAlert(false,'请先勾选同意')
      }
      // 记录用户名到本地存储
      localStorage.setItem('xtx-uname', username.value)
	  let flag = false
	  //进行验证,获取当前的账户名字和密码
	  localStorage.setItem('loca_id',username.value)
	  localStorage.setItem('local_mima',password.value)
	  let user_id_local =  localStorage.getItem('loca_id')
	  let user_mima_local = localStorage.getItem('local_mima')
	  //登录判断
	  for(let i=0;i<arr.length;i++)
	  {
		  if(user_id_local == arr[i].username && user_mima_local==arr[i].password )
		  {
			  flag = true
			  break;
		  }
	  }
	  if(flag)
      // 跳转到首页
		{
			myAlert(true,'登录成功')
			setTimeout(()=>{
				location.href = './index.html'
				document.querySelector('.remember').checked = false
			},1500)
		}
	 else{
		 myAlert(false,'登陆失败,账号或密码错误')
	 }
})
